package com.cvit.cn.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.cn.bean.ExcelBean;
import com.cvit.cn.bean.VendorsQuotation;
import com.cvit.cn.dao.VendorsQuotationMapper;
import com.cvit.cn.test.ExcelUtil;

@Service
public class VendorsQuotationService {
	@Autowired
	VendorsQuotationMapper vendorsQuotationMapper;
	
	public List<VendorsQuotation> getAll() {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.selectByExample(null);
	}

	public void updataSupplierType(VendorsQuotation vq) {
		// TODO Auto-generated method stub
		vendorsQuotationMapper.updataSupplierType(vq);
	}

	public List<VendorsQuotation> getSupplierTypeSuccess(String vendorsId, String releaseId, String supplierType) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.getSupplierTypeSuccess(vendorsId,releaseId,supplierType);
	}

	public List<VendorsQuotation> getSupplierTypeRelease(String vendorsId, String supplierType) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.seleSupplierTypeRelease(vendorsId,supplierType);
	}

	public List<VendorsQuotation> getNoSupplierTypeRelease(String vendorsId) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.seleNoSupplierTypeRelease(vendorsId);
	}

	public List<VendorsQuotation> getNoIngSupplierTypeRelease(String vendorsId) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.seleNoIngSupplierTypeRelease(vendorsId);
	}

	public int addQuotations(VendorsQuotation vendorsQuotation) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.insertSelective(vendorsQuotation);
	}

	public List<VendorsQuotation> getReleaseById(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.seleReleaseById(releaseId);
	}

	public List<VendorsQuotation> getSupplierTypeThree(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.getSupplierTypeThree(releaseId);
	}

	public List<VendorsQuotation> getSupplierTypeOne(String releaseId) {
		// TODO Auto-generated method stub
		return vendorsQuotationMapper.getSupplierTypeOne(releaseId);
	}

	/**
	 * 导出Excel
	 * */
	public XSSFWorkbook exportExcelInfo(String VendorsQuotationData,String vendorsId,String releaseId) throws Exception {  
	    //根据条件查询数据，把数据装载到一个list中  
	    List<VendorsQuotation> list = vendorsQuotationMapper.getVendorsById(vendorsId,releaseId);
	    List<ExcelBean> excel=new ArrayList<ExcelBean>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<Integer, List<ExcelBean>>();
	    XSSFWorkbook xssfWorkbook=null;
	    //设置标题栏
	    excel.add(new ExcelBean("公司名","supplierName",0));
	    excel.add(new ExcelBean("部门","department",0));
	    excel.add(new ExcelBean("物品名","commodityName",0));
	    excel.add(new ExcelBean("物品类型","commodityCategory",0));
	    excel.add(new ExcelBean("物品型号","specificationModel",0));
	    excel.add(new ExcelBean("单位","company",0));
	    excel.add(new ExcelBean("数量","number",0));
	    excel.add(new ExcelBean("单价","unitPrice",0));
	    excel.add(new ExcelBean("总价","money",0));
	    excel.add(new ExcelBean("总合计","total",0));
	    excel.add(new ExcelBean("备注","notes",0));
	    //excel.add(new ExcelBean("备注","remarks",0));
	    map.put(0, excel);
	    String sheetName = VendorsQuotationData;
	    //调用ExcelUtil的方法
	    xssfWorkbook = ExcelUtil.createExcelFile(VendorsQuotation.class, list, map, sheetName);
	    return xssfWorkbook;
	}

}
